using System;
using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity;
using System.Linq;
using Forging2.DataBase.QID_IGDATA_ZY;




namespace Forging2.DataBase
{
    public partial class IGDataDbContext : DbContext
    {
        //public IGDataDbContext()
        //    : base("name=Model_QID_IGData_ZY")
        //{
        //}
        public IGDataDbContext(string constring = @"data source=vsermes;initial catalog=QID_IGData_ZY;user id=AppUser;password=appuser123456;multipleactiveresultsets=True;application name=EntityFramework") : base(constring)
        {

        }

        public virtual DbSet<bas_equipment_zy> bas_equipment_zy { get; set; }
        public virtual DbSet<bas_plcaddress_zy> bas_plcaddress_zy { get; set; }
        public virtual DbSet<run_data_detail> run_data_detail { get; set; }
        public virtual DbSet<run_data_main> run_data_main { get; set; }

        public virtual DbSet<dy_clamp_log> dy_clamp_log { get; set; }
        public virtual DbSet<dy_plan_icmo> dy_plan_icmo { get; set; }
        public virtual DbSet<dy_plc_parameter> dy_plc_parameter { get; set; }
        public virtual DbSet<dy_route_line> dy_route_line { get; set; }
        public virtual DbSet<dy_workrecord> dy_workrecord { get; set; }
        public virtual DbSet<dy_workrecord_detail> dy_workrecord_detail { get; set; }

        public virtual DbSet<V_WorkRecord> V_WorkRecord { get; set; }

        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            modelBuilder.Entity<bas_equipment_zy>()
                .HasMany(e => e.bas_plcaddress_zy)
                .WithRequired(e => e.bas_equipment_zy)
                .HasForeignKey(e => e.EQUIPMENT_GID)
                .WillCascadeOnDelete(false);

            modelBuilder.Entity<bas_equipment_zy>()
                .HasMany(e => e.run_data_main)
                .WithRequired(e => e.bas_equipment_zy)
                .HasForeignKey(e => e.EQUIPMENT_GID)
                .WillCascadeOnDelete(false);

            modelBuilder.Entity<bas_plcaddress_zy>()
                .Property(e => e.DB_MONITOR)
                .IsUnicode(false);

            modelBuilder.Entity<run_data_detail>()
                .Property(e => e.ID)
                .HasPrecision(18, 0);

            modelBuilder.Entity<run_data_detail>()
                .Property(e => e.GET_ID)
                .HasPrecision(9, 0);

            modelBuilder.Entity<run_data_main>()
                .Property(e => e.GET_ID)
                .HasPrecision(9, 0);

            modelBuilder.Entity<run_data_main>()
                .Property(e => e.FORGING_NO)
                .IsUnicode(false);

            modelBuilder.Entity<run_data_main>()
                .Property(e => e.DATA_START_NO)
                .HasPrecision(10, 0);

            modelBuilder.Entity<run_data_main>()
                .Property(e => e.DATA_END_NO)
                .HasPrecision(10, 0);

            modelBuilder.Entity<run_data_main>()
                .HasMany(e => e.run_data_detail)
                .WithRequired(e => e.run_data_main)
                .WillCascadeOnDelete(false);

            modelBuilder.Entity<dy_plan_icmo>()
                .Property(e => e.OrderWeight)
                .HasPrecision(8, 3);

            modelBuilder.Entity<dy_plan_icmo>()
                .Property(e => e.ProcessWeight)
                .HasPrecision(8, 3);

            modelBuilder.Entity<dy_route_line>()
                .Property(e => e.ProcessWeight)
                .HasPrecision(8, 3);

            modelBuilder.Entity<dy_clamp_log>()
                .Property(e => e.WorkPieceTemperature)
                .HasPrecision(7, 3);
        }
    }
}
